package com.ziyunying.weather.di

import android.content.Context
import com.ziyunying.weather.api.QWeatherApi
import com.ziyunying.weather.common.cache.WeatherCacheManager
import com.ziyunying.weather.repository.WeatherRepository
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object WeatherModule {
    
    @Provides
    @Singleton
    fun provideContext(@ApplicationContext context: Context): Context {
        return context
    }

    @Provides
    @Singleton
    fun provideWeatherRepository(
        qWeatherApi: QWeatherApi,
        weatherCacheManager: WeatherCacheManager
    ): WeatherRepository {
        return WeatherRepository(
            qWeatherApi = qWeatherApi,
            cacheManager = weatherCacheManager,
        )
    }

    @Provides
    @Singleton
    fun provideQWeatherApi(@ApplicationContext context: Context): QWeatherApi {
        return QWeatherApi(
            context = context,
            host = "pj6apvvcjt.re.qweatherapi.com",
            privateKey = "MC4CAQAwBQYDK2VwBCIEIBHdcUArk7Zk4Avfd6GFfNX2BnCb1pOixeq71nz73PAK",
            projectId = "462H8EM47E",
            kid = "TNPKEAEX9W"
        )
    }
}